package com.etc.myblog.ser;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.myblog.biz.ArticleBiz;
import com.etc.myblog.biz.ScolumnBiz;
import com.etc.myblog.biz.UserBiz;
import com.etc.myblog.entity.Article;
import com.etc.myblog.entity.User;
import com.etc.myblog.entity.UserArtCount;

public class RankSer extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ArticleBiz artBiz = new ArticleBiz();
		UserBiz userBiz = new UserBiz();
		ScolumnBiz scolBiz = new ScolumnBiz();
		//文章周排行
		List<Article> artListTop= new ArrayList<>();
		artListTop = artBiz.findArtTopWeek();
		//推荐文章
		List<Article> artTop = new ArrayList<>();
		artTop = artBiz.findClickTop();
		//专家排行
		
		List<User> authorList = new ArrayList<>();
		authorList = userBiz.findAuthor();
		List<UserArtCount> userartCount = new ArrayList<>();
		
		for(int i=0; i<authorList.size(); i++) {
			UserArtCount uacount = new UserArtCount();
			uacount.setUser(authorList.get(i));
			uacount.setArticleCount(artBiz.articleCount(authorList.get(i).getUserId()));
			uacount.setArticleView(artBiz.articleView(authorList.get(i).getUserId()));
			userartCount.add(uacount);
		}
		
		request.setAttribute("authorTop", userartCount);
		request.setAttribute("artTop", artTop);
		request.setAttribute("artListTop", artListTop);
		request.getRequestDispatcher("user/webRank.jsp").forward(request,response);
		
	}

}
